package com.ruoyi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.domain.News;
import com.ruoyi.domain.NewsWithType;
import com.ruoyi.domain.entity.ForumPost;
import com.ruoyi.domain.entity.Stock;
import com.ruoyi.domain.vo.SearchVo;
import com.ruoyi.domain.vo.StockDetailVo;
import com.ruoyi.exception.BaseException;
import com.ruoyi.mapper.ForumPostMapper;
import com.ruoyi.mapper.NewsMapper;
import com.ruoyi.mapper.StockMapper;
import com.ruoyi.service.DouBaoAIService;
import com.ruoyi.service.StockService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

@Service
public class StockServiceImpl implements StockService {
    @Resource
    private StockMapper stockMapper;
    @Resource
    private NewsMapper newsMapper;
    @Resource
    private ForumPostMapper forumPostMapper;
    @Resource
    private DouBaoAIService douBaoAIService;

    @Override
    public Stock getStockDetail(Integer stockId) {
        Stock stock = stockMapper.selectById(stockId);
        if(stock == null){
            throw new BaseException("股票信息不存在");
        }
        return stock;
    }

    @Override
    public String getStockDescription(Integer stockId) {
        Stock stock = stockMapper.selectById(stockId);
        if(stock == null){
            throw new BaseException("股票信息不存在");
        }
        //调用AI接口获取股票简介
        String stockCode = stock.getStockCode();
        String question = "给我股票代码为"+stockCode+"股票的简介，包括股票代码，所属公司、行业、实控人、上市状态等方面，不要超过200字";
        return douBaoAIService.getAIAsk(question);
    }

    @Override
    public List<Stock> searchStocks(String keyword) {
        return stockMapper.getSearchList(keyword);
    }
}